package com.ltg.admin.utils;


import lombok.Data;

@Data
public class Result<T> {

    private T data;
    private String message;
    private Integer code;


    public static <T> Result success() {
        return success(200, "操作成功", null);
    }

    public static <T> Result success(Integer code, String msg, T data) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        result.setMessage(msg);
        return result;
    }

    public static <T> Result success( T data) {
        Result result = new Result();
        result.setMessage("success");
        result.setCode(0);
        result.setData(data);
        return result;
    }

    public static <T> Result success(ResultCode resultCode, T data) {
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMessage(result.message);
        result.setData(data);
        return result;
    }

    public static <T> Result error(String message) {
        return error(400, message, null);
    }


    public static <T> Result error(ResultCode resultCode) {
        Result<T> result = new Result<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }

    public static <T> Result error(int code, String msg, T data) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }

}
